﻿@model Xms.Web.Customize.Models.EntityModel

<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">
            <a data-toggle="collapse"
               href="#collapseTwo">
                <strong>@app.PrivilegeTree?.LastOrDefault().DisplayName</strong>
            </a>
        </h3>
    </div>
    <div id="collapseTwo" class="panel-collapse collapse in">
        <div class="panel-body">
            <div id="gridview">
                <div class="mb-2 toolbar">
                    <form action="/@app.OrganizationUniqueName/customize/@app.ControllerName/@app.ActionName" method="get" id="searchForm" role="form">
                        @Html.ValidationSummary()
                        @Html.HiddenFor(x => x.SolutionId)
                        @Html.HiddenFor(x => x.EntityGroupId)
                        <div class="row">
                            <div class="col-sm-8">
                                <div class="btn-group btn-group-sm">
                                    <a class="btn btn-info" href="@("/"+app.OrganizationUniqueName)/customize/entity/createentity?solutionid=@Model.SolutionId" id="createBtn"><span class="glyphicon glyphicon-plus-sign"></span> @app.T["add"]</a>
                                    <button type="button" class="btn btn-warning" data-action="/customize/entity/deleteentity" data-role="delete" data-tooltip="@app.T["confirm_delete"]"><span class="glyphicon glyphicon-trash"></span> @app.T["batch_delete"]</button>
                                </div>
                            </div>
                            <div class="col-sm-4">
                                <div class="input-group input-group-sm">
                                    @Html.TextBoxFor(x => x.Name, new { @class = "form-control", @placeholder = @app.T["entity_name"] })
                                    <span class="input-group-btn">
                                        <button type="submit" class="btn btn-info btn-block grid-searcher"><span class="glyphicon glyphicon-search"></span> @app.T["search"]</button>
                                    </span>
                                </div>
                            </div>
                        </div>
                    </form>
                    <!-- /input-group -->
                </div>

                <div class="table-datagrid-view">
                    <div class="datagrid-view"></div>
                </div>
            </div>
        </div>
    </div>
</div>

@section Header {
    <link href="~/content/js/jquery-ui-1.10.3/themes/base/jquery.ui.all.css?v=@app.PlatformSettings.VersionNumber" rel="stylesheet">
    <link href="~/content/js/grid/pqgrid.dev.css?v=@app.PlatformSettings.VersionNumber" rel="stylesheet">
    <link id="themeLink" href="~/content/css/theme/@(app.Theme).css" rel="stylesheet" />
}
@section Scripts {
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.button.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.mouse.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.autocomplete.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.draggable.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.resizable.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.tooltip.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="~/content/js/fetch.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="~/content/js/common/filters.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/grid/pqgrid.dev.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/grid/localize/pq-localize-zh.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/cdatagrid.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery.bootpag.min.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery.form.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script>
        var pageUrl = '@app.Url';
        var solutionid = '@Model.SolutionId';
        $(function () {
            pageUrl = '@app.Url';
            var theaders = {
                'entity_name': '@app.T["entity_name"]',
                'entity_localizedname': '@app.T["entity_localizedname"]',
                'entity_authorization': '@app.T["entity_authorization"]',
                'entity_loged': '@app.T["entity_loged"]',
                'entity_createdon': '@app.T["entity_createdon"]',
                'operation':'@app.T["operation"]'
            }
            //列数据配置数据
            var columnConfigs = [
            //从新配置复选框列的渲染方式，
                {
                    title: "", dataIndx: "recordid", maxWidth: 48, minWidth: 48, align: "center", resizable: false,
                    type: 'checkBoxSelection', cls: 'ui-state-default', sortable: false, editable: false,
                    render: function (ui) {
                      //  console.log(ui)
                        return '<input type="checkbox" value="' + ui.rowData.entityid + '" name="recordid" class="">'
                    },
                    cb: { all: true, header: true }
                },
                {
                    title: "", dataIndx: "hidden", maxWidth: 30, minWidth: 30, align: "center", resizable: false,
                     cls: 'ui-state-default', sortable: false, editable: false,
                    hidden:true,
                    render: function (ui) {
                        //  console.log(ui)
                        return '<input type="hidden" value="' + ui.rowData.entityid + '" name="componenttypename" class="">'
                    },
                    cb: { all: true, header: true }
                },
                { "dataIndx": "name", "title": theaders.entity_name, editable: false, "dataType": "string", "width": 250, "isprimaryfield": false, "attributetypename": "string" },
                { "dataIndx": "localizedname", "title": theaders.entity_localizedname, "dataType": "string", editable: false, "width": 150, "isprimaryfield": false, "attributetypename": "string" },
                {
                    "dataIndx": "authorizationenabled", "title": theaders.entity_authorization, editable: false, "dataType": "string", "width": 100, "isprimaryfield": false, "attributetypename": "string", render: function (ui, a, b) {
                        var datas = ui.rowData;
                        var dataIndx = ui.dataIndx;
                        var column = ui.column;
                        var recordid = datas[dataIndx];

                        if (recordid == true) {
                            return '<span class="label label-success">启用</span>'
                        } else {
                            return '<span class="label label-default">禁用</span>'
                        }
                    }
                },
                { "dataIndx": "logenabled", "title": theaders.entity_loged, editable: false, "dataType": "string", "width": 100, "isprimaryfield": false, "attributetypename": "string", render: function (ui, a, b) {
                        var datas = ui.rowData;
                        var dataIndx = ui.dataIndx;
                        var column = ui.column;
                        var recordid = datas[dataIndx];

                        if (recordid == true) {
                            return '<span class="label label-success">启用</span>'
                        } else {
                            return '<span class="label label-default">禁用</span>'
                        }
                    } },
                 { "dataIndx": "createdon", "title": theaders.entity_createdon, editable: false, "dataType": "string", "width": 150, "isprimaryfield": false, "attributetypename": "string" },
                {
                    title: "操作", editable: false, minWidth: 120,width:120, notHeaderFilter: true, editable: false, sortable: false, render: function (ui) {
                        var datas = ui.rowData;
                        var dataIndx = ui.dataIndx;
                        var column = ui.column;
                        var recordid = datas[dataIndx];
                        var html = ''
                        if (datas.iscustomizable) {
                            html = '<a class="btn btn-default btn-xs" href="@("/"+app.OrganizationUniqueName)/customize/entity/editentity?id=' + datas.entityid + '&solutionid='+solutionid+'"><span class="glyphicon glyphicon-edit"></span> 编辑</a> <a class="btn btn-warning btn-xs" href=\'javascript:delRecord("' + datas.entityid + '","/customize/entity/deleteentity",false,deleteCallBack,null,"删除后相关数据也将一并删除，请提前备份数据",true)\'><span class="glyphicon glyphicon-trash"></span> 删除</a>';
                        } else {
                            html = '<a class="btn btn-default btn-xs" href="@("/"+app.OrganizationUniqueName)/customize/entity/editentity?id=' + datas.entityid + '&solutionid='+solutionid+'"><span class="glyphicon glyphicon-edit"></span> 编辑</a>';
                        }
                        return html
                    }
                }
            ];
            var url = ORG_SERVERURL + '/customize/entity/index?LoadData=true&';
            var $form = $('#searchForm');
            var roles_filters = new XmsFilter();
            var datagridconfig = {
                scrollModel: { autoFit: true },
                baseUrl: url,
                columnConfigs: columnConfigs,//字段配置信息
                context: $('#gridview'),//底部操作按钮方法触发
                filters: roles_filters,//post提交时过滤条件
                searchForm: $form//GET提交时查询的数据
            };
            $('.datagrid-view').xmsDataTable(datagridconfig);
            Xms.Web.Event.localStorageEvent.on('list_entity_rebind', function () {
                setTimeout(function () {
                    location.reload();
                },100)
            });

        });
        function deleteCallBack() {
            $('#loader').remove();
            rebind();
            Xms.Web.Event.publish('refreshtree');
        }
        function rebind() {
            $('.datagrid-view').cDatagrid('refreshDataAndView');
        }

        function delRecord(id, action, refresh, onsuccess, onerror, confirmtext, isconfirmagain) {
            Xms.Web.Del(id, action, refresh, onsuccess, onerror, confirmtext, isconfirmagain, {

                content: '<div class="form-group"><h3 style="color:red; font-size:12px;"><label class="checkbox-inline"><input class="" style="font-size:12px; margin:0" id="anddeltable" type="checkbox" value="true" checked="checked" /><span style="font-size:18px;" class="pl-5">同时删除表？</span></label></h3></div>',
                checkOk: function (opts) {
                    var ckb = $('#anddeltable').prop('checked');
                    opts.postdata = {
                        DeleteTable: ckb
                    }

                    return true;
                }
            });
        }
    </script>
}